﻿using InTheHand.Bluetooth;
using System;

namespace BLE_Keypad_Tool
{
	internal class Constants
	{
		// Service UUIDs
		public static BluetoothUuid UUID_NORDIC_UART = BluetoothUuid.FromGuid(new Guid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E"));

		// Characteristic UUIDs
		public static BluetoothUuid UUID_NORDIC_RX = BluetoothUuid.FromGuid(new Guid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"));
		public static BluetoothUuid UUID_NORDIC_TX = BluetoothUuid.FromGuid(new Guid("6E400003-B5A3-F393-E0A9-E50E24DCCA9E"));

		public static BluetoothUuid UUID_MANUFACTURER_NAME = BluetoothUuid.FromShortId(0x2A29);
		public static BluetoothUuid UUID_MODEL_NUMBER = BluetoothUuid.FromShortId(0x2A24);
		public static BluetoothUuid UUID_SERIAL_NUMBER = BluetoothUuid.FromShortId(0x2A25);
		public static BluetoothUuid UUID_FIRMWARE_REVISION = BluetoothUuid.FromShortId(0x2A26);
		public static BluetoothUuid UUID_HARDWARE_REVISION = BluetoothUuid.FromShortId(0x2A27);
		public static BluetoothUuid UUID_SOFTWARE_REVISION = BluetoothUuid.FromShortId(0x2A28);

		public const string COMMAND_SEPARATOR = "!!!";
		public static string COMMAND_PREFIX = $"BKTC{COMMAND_SEPARATOR}";
		public const string COMMAND_BEGIN_TRANSFER = "BEGIN";

		public const int COMMAND_QUERY_KEYPAD_CONFIG = 0;
	}

	internal class Utilities
	{
		public static string format_device_id(string address)
		{
			for (int index = 2; index < address.Length; index += 3) address = address.Insert(index, ":");
			return address;
		}

		public static (string name, string id) extract_device_name_and_id(string name_id)
		{
			string[] array = name_id.Replace(":", "").Split(new string[] { "(", ")" }, StringSplitOptions.RemoveEmptyEntries);
			return (array[0].Trim(), array[1].Trim());
		}
	}
}
